<template>
  <div class="login">
    <div class="content">
      <div class="bg" />
      <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="ruleForm">
        <h1>注册</h1>
        <el-form-item label="用户名" prop="name">
          <el-input v-model="ruleForm.name" />
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="ruleForm.password" show-password />
        </el-form-item>
        <el-form-item label="确认密码" prop="password1">
          <el-input v-model="ruleForm.password1" show-password />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="register">注册</el-button>
          <el-button @click="toLogin">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import Util from '../libs/util'

export default {
  data() {
    return {
      ruleForm: {
        name: '',
        password: ''
      },
      rules: {
        name: [{
          required: true,
          message: '请输入用户名',
          trigger: 'blur'
        },
        {
          min: 6,
          max: 20,
          message: '用户名长度在 6 到 20 位字符',
          trigger: 'blur'
        }
        ],
        password: [{
          required: true,
          message: '请输入密码',
          trigger: 'blur'
        },
        {
          min: 6,
          max: 20,
          message: '密码长度为 6 到 20 位字符',
          trigger: 'blur'
        }
        ],
        password1: [{
          required: true,
          message: '请输入密码',
          trigger: 'blur'
        },
        {
          min: 6,
          max: 20,
          message: '密码长度为 6 到 20 位字符',
          trigger: 'blur'
        }
        ]
      }
    }
  },
  mounted: function() {},
  methods: {
    // 登录
    register() {
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          alert('submit!')
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    toLogin() {
      this.$router.push({
        name: 'Login'
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.login {
    overflow: hidden;
    height: 100%;
    .content {
        position: absolute;
        left: 50%;
        top: 50%;
        padding: 150px;
        transform: translate(-50%,-50%);
        width: 650px;
        .bg {
            position: absolute;
            left: 0;
            top: 0;
            bottom: 0;
            right: 0;
            background: #fff;
            opacity: 0.9;
            border-radius: 10px;
            box-shadow: 0 10px 50px #aaa;
        }
        .ruleForm {
            position: relative;
            z-index: 1;
            h1 {
                padding-bottom: 20px;
                text-align: center;
            }
        }
    }
}
</style>
